package Stack.Brackets;

import Stack.Stack.Stack;

public class BracketsMatch {
    public static void main(String[] args) {
        String s = "(长安)(福()特)()())";
        System.out.println(match(s));
    }

    public static boolean match(String s) {
        Stack<Character> stack = new Stack<>();
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == '(') {
            //if((s.charAt(i)+"").equals("(")) {
                //push
                stack.push(s.charAt(i));
            }
            if (s.charAt(i) == ')') {
                //if stack is null now, return false
                if (stack.isEmpty()) {
                    return false;
                }
                //pop
                stack.pop();
            }
        }
        if (stack.isEmpty()){
            return true;
        }
        //if stack is not null, proof the number of '(' is more than ')', return false
        return false;
    }
}
